import java.util.Stack;

/**
 * @Author: Lenovo
 * @Date: 2024/7/17 23:52
 * @description:
 */
public class MinStack {
    public Stack<Integer> stack;
    public Stack<Integer> minstack;
    public MinStack() {
        stack = new Stack();
        minstack = new Stack();
    }

    public void push(int val) {
        stack.push(val);
        if (minstack.isEmpty()){
            minstack.push(val);
        }else{
            int peek = minstack.peek();
            if (val <= peek){
                minstack.push(val);
            }
        }
    }

    public void pop() {
        if (minstack.isEmpty()){
            return;
        }
        int popVal = stack.pop();
        if (popVal == minstack.peek()){
            minstack.pop();
        }
    }

    public int top() {
        if (stack.isEmpty()){
            return -1;
        }
        return stack.peek();
    }

    public int getMin() {
        if (minstack.isEmpty()){
            return -1;
        }
        return minstack.peek();
    }
}
